//groupBy([6.1, 4.2, 6.3], Math.floor);
//{4:[4.2],6:[6.1,6.2]};
//groupBy(['one', 'two', 'three'], 'length')
//{3:['one','two'],5:['three']};
function groupBy(arr, fn) {
    let res = {};
    for (let i = 0; i < arr.length; i++) {
        let temp;
        if (typeof fn == 'function') {
            temp = fn(arr[i]);
        } else {
            temp = arr[i][fn];
        }
        if (!res[temp]) {
            res[temp] = [];
        }
        res[temp].push(arr[i]);
    }
    return res;
}

console.log(groupBy([6.1, 4.2, 6.3], Math.floor));
console.log(groupBy(['one', 'two', 'three'], 'length'));